
package org.ipti.br.tag.bean.questionnaire;

import org.ipti.br.tag.bean.AppBaseBean;
import org.ipti.br.tag.bo.CampaignBO;
import org.ipti.br.tag.entity.Campaign;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;

/**
 *
 * @author FelipeMSX
 */
@ManagedBean(name="campaignManagerB")
@ViewScoped
public class CampaignMB extends AppBaseBean implements Serializable {
    
    @Inject private CampaignBO campaignBO;
    
    private List<Campaign> campaignList;
    
    public CampaignMB(){
       
    }
    
    @PostConstruct
    public void init(){
       this.campaignList = campaignBO.findAll();
    }
    
    public List<Campaign> loadCampaignList(){
        return campaignList;
    }
    
    public void saveChanges(){
        try{   
            for(Campaign element: campaignList){
                campaignBO.edit(element);
            }
            addInfoMessage(":campaignManageForm:message", "Sucesso", "Salvo com sucesso no servidor");
        }catch(Exception e){       
            e.printStackTrace();
            addErrorMessage(":campaignManageForm:message", "Erro ao salvar os dados no servidor", "Não foi possível salvar");
            
        }
    }
    
    public void rediretToHomepage(){
        redirect("/educational/home/home.xhtml");
    }

    public List<Campaign> getCampaignList() {
        return campaignList;
    }

    public void setCampaignList(List<Campaign> campaignList) {
        this.campaignList = campaignList;
    }
    
}
